package com.sdry.service.impl.jyy;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sdry.mapper.jyy.ReceiveMapper;
import com.sdry.model.jyy.Receive;
import com.sdry.model.jyy.Up;
import com.sdry.model.llm.LlmRegionStock;
import com.sdry.model.llm.LlmWarehouseStock;
import com.sdry.model.lz.Customer;
import com.sdry.model.lz.Materiel;
import com.sdry.model.lz.WarehouseRegionLocation;
import com.sdry.service.jyy.ReceiveService;
/**
 *
 *@ClassName: ReceiveService
 *@Description: 收货计划
 *@Author jyy
 *@Date 2019-04-18 09:35:01
 *@version 1.0
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ReceiveServiceImpl implements ReceiveService {
	@Resource ReceiveMapper ReceiveMapper;
	/** 
	 * 根据主键id查询实体
	 * @param id 主键id
	 * @return 实体
	*/
	public Receive queryById(Long id) {
		return ReceiveMapper.queryById(id);
	}
	/** 
	 * 条件查询所有
	 * @param param 实体条件
	 * @return 实体集合
	*/
	public List<Receive> queryAllByMution(Receive param) {
		return ReceiveMapper.queryAllByMution(param);
	}
	/** 
	 * 条件分页查询
	 * @param param 实体条件
	 * @return 实体集合
	*/
	public List<Receive> findPageByMution(Receive param) {
		return ReceiveMapper.findPageByMution(param);
	}
	/** 
	 * 条件查询记录数
	 * @param param 实体条件
	 * @return 实体集合
	*/
	public Integer selectCountByMution(Receive param) {
		return ReceiveMapper.selectCountByMution(param);
	}
	/** 
	 * 插入返回id
	 * @param param 实体条件
	 * @return 主键id
	*/
	public Long insert(Receive param) {
		return ReceiveMapper.insert(param);
	}
	/** 
	 * 根据主键更新 返回影响行数
	 * @param param 实体条件
	 * @return 影响行数
	*/
	public Integer update(Receive param) {
		return ReceiveMapper.update(param);
	}
	/** 
	 * 根据主键拼接的字符串删除返回影响行数
	 * @param ids 主键拼接的字符串
	 * @return 影响行数
	*/
	public Integer delete(String ids) {
		return ReceiveMapper.delete(ids);
	}
	/**
	 * 根据物料id查询物料的仓库信息
	 * @param mid 物料id
	 * @return
	 */
	@Override
	public List<LlmWarehouseStock> selectWarehouseByMid(Up up) {
		
		List<LlmWarehouseStock> list = ReceiveMapper.selectWarehouseByMid(up);
		Long mid = up.getMid();
		Long customerId = up.getCustomerId();
		if(list.size() > 0){
			for(LlmWarehouseStock ws : list){
				ws.setRemark(mid+"");
				ws.setStatus(customerId+"");
				List<LlmRegionStock> regionList = ReceiveMapper.selectRegionStockByWarehouseId(ws);
				if(regionList.size() > 0){
					for(LlmRegionStock rs : regionList){
						rs.setRemark(mid+"");
						rs.setRegion_status(customerId+"");
						List<WarehouseRegionLocation> locationList = ReceiveMapper.selectLocationStockByRegionId(rs);
						rs.setLocationList(locationList);
					}
				}
				ws.setRegionList(regionList);
			}
		}
		return list;
	}
	
	/**
	 * 根据物料产品码查询物料所有信息
	 * @param maNum 物料产品码
	 * @return
	 */
	@Override
	public Materiel selectMaByMaNum(String maNum) {
		return ReceiveMapper.selectMaByMaNum(maNum);
	}
	
	/**
	 * 根据供应商 名称 查询相关物料信息
	 * @param client
	 * @return
	 */
	@Override
	public List<Materiel> materielList(long id) {
		return ReceiveMapper.materielList(id);
	}
	
	/**
	 * 根据物料id查询供应商
	 */
	@Override
	public List<Customer> selectCustomerByMid(Long id) {
		return ReceiveMapper.selectCustomerByMid(id);
	}
	
	/**
	 * 根据物料id查询库区位置
	 */
	@Override
	public Materiel queryMaterielLocationById(Long mid) {
		return ReceiveMapper.queryMaterielLocationById(mid);
	}
}
